package com.yunzhong.appointment.personal.service.impl;

import com.yunzhong.appointment.entity.Area;
import com.yunzhong.appointment.entity.City;
import com.yunzhong.appointment.entity.Patient;
import com.yunzhong.appointment.entity.Province;
import com.yunzhong.appointment.mapper.AreaMapper;
import com.yunzhong.appointment.mapper.CityMapper;
import com.yunzhong.appointment.mapper.PatientMapper;
import com.yunzhong.appointment.mapper.ProvinceMapper;
import com.yunzhong.appointment.personal.service.personalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class personServiceImpl implements personalService {

    @Autowired
    private PatientMapper patientMapper;
    @Autowired
    private ProvinceMapper provinceMapper;
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private CityMapper cityMapper;
    @Override
    public Patient queryByName(String id) {
        return patientMapper.selectByName(id);
    }

    @Override
    public List<Province> queryByPro() {
        return provinceMapper.selectByPro();
    }

    @Override
    public List<Area> queryByArea(String id) {
        return areaMapper.selectByArea(id);
    }

    @Override
    public List<City> queryByCity(String id) {
        return cityMapper.selectByCity(id);
    }

    @Override
    public StringBuilder queryByIde(Patient pat) {
        String ide=pat.getPatientUid();
        StringBuilder sb = new StringBuilder();
        String a=ide.substring(0,3);
        String b="***********";
        String c = ide.substring(ide.length() - 4, ide.length());
        sb.append(a).append(b).append(c);
        return sb;
    }

    @Override
    public StringBuilder queryByTel(Patient pat) {
        String tel=pat.getPatientTel();
        StringBuilder sb = new StringBuilder();
        String a=tel.substring(0,3);
        String b="*****";
        String c = tel.substring(tel.length() - 3, tel.length());
        sb.append(a).append(b).append(c);
        return sb;
    }

    @Override
    public int edit(Patient patient) {
        String pname = patientMapper.queryByPid(patient.getProvinceId());
        String cname = patientMapper.queryByCid(patient.getCityId());
        String aname = patientMapper.queryByAid(patient.getAreaId());
        patient.setProvinceName(pname);
        patient.setCityName(cname);
        patient.setAreaName(aname);
        return patientMapper.updateByPrimaryKeySelective(patient);
    }

    @Override
    public Patient queryById(String patientId) {
        return patientMapper.selectByPrimaryKey(patientId);
    }
}
